<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jquery-2-后代/子选择器</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <style>
        /* div>p{
            color: red;
        } */
    </style>
    <script>
        $(function () {
            // 后代选择器
            // $("ul li").css("color", "green");
            //后代选择器可用find()代替
            $("ul").find(' li').css("color", "red");

            //子选择器：只获取子节点的多一个DOM对象
            // $('.box1>p').css('color', 'blue')
            //子选择器可用children()代替
            $('.box1').children('p').css('color', 'pink')
        });
    </script>
</head>

<body>
    <ul>
        <li>后代选择器</li>
        <li>
            <span>span后代选择器</span>
        </li>
        <li>
            <span>
                <p>p后代选择器</p>
            </span>
        </li>
    </ul>

    <div class="box1">
        <p>子选择器</p>
        <span>
            <p>span子选择器</p>
        </span>
    </div>
</body>

</html>